package com.hzxy.yiyid.web.module.runner;

import com.hzxy.yiyid.web.module.cache.MedicineDataCache;
import com.hzxy.yiyid.web.module.utils.wordFilter.WordContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName CacheFlushRunner
 * @Description TOOD
 * @Author RAICOM2023
 * @Date 2023/4/29 17:17
 * @Version 1.0
 **/
@Component
public class CacheFlushRunner implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(CacheFlushRunner.class);

    @Resource
    private MedicineDataCache medicineDataCache;

    @Resource
    private WordContext wordContext;

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        try{
            medicineDataCache.flushCache();
        }catch (Exception e){
            logger.error("初始化缓存错误",e);
        }

        try{
            wordContext.initKeyWord();
        }catch (Exception e){
            logger.error("初始化症状匹配词库失败",e);
        }
    }
}
